package com.itchen.controller;

import com.itchen.pojo.Adder;
import com.itchen.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/15
 */
@Controller
public class Usercontroller {


/*    @RequestMapping("/save")
    @ResponseBody
    public String save(@RequestParam("name") String username, String password) {
        System.out.println("Usercontroller save ..." + username + password);
        return "{'name':'niuma'}";

    }*/


    @RequestMapping("/user")
    @ResponseBody
    public String user(@RequestParam("name") String username) {
        System.out.println("usernaem ---> " + username);
        return "{'name':'niuma'}";

    }


    @RequestMapping("/save")
    @ResponseBody
    public String save(@RequestParam("name") String username, String password) {
        System.out.println("Usercontroller save ..." + username + password);
        return "{'name':'niuma'}";

    }


    @RequestMapping("/namepass")
    @ResponseBody
    public String namepass(User username) {
        System.out.println(username);

        return "{'name':'niuma'}";

    }


    @RequestMapping("/namepass1")
    @ResponseBody
    public String npa(User username) {
        System.out.println(username);

        return "{'name':'niuma'}";

    }

    @RequestMapping("/array")
    @ResponseBody
    public String array(String[] likes) {
        System.out.println(Arrays.toString(likes));

        return "{'name':'niuma'}";

    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(List<String> likes) {
        System.out.println(likes);

        return "{'name':'niuma'}";

    }


    @RequestMapping("/abc")
    @ResponseBody
    public String get(@RequestBody List<User> likes) {
        System.out.println(likes);

        return "{'name':'niuma'}";

    }

    @RequestMapping("/selectById")
    @ResponseBody
    public User selectById() {
        User user = new User();
        user.setName("张三");
        user.setAge(20);
        Adder adder = new Adder();
        adder.setprovince("湖南");
        adder.setCity("邵阳");
        user.setAddress(adder);

        return user;

    }


    @RequestMapping("/selectAll")
    @ResponseBody
    public List<User> selectAll() {
        User user = new User();
        user.setName("张三");
        user.setAge(20);
        Adder adder = new Adder();
        adder.setprovince("湖南");
        adder.setCity("邵阳");
        user.setAddress(adder);

        User user1 = new User();
        user1.setName("李四");
        user1.setAge(50);
        Adder adder1 = new Adder();
        adder1.setprovince("朝阳");
        adder1.setCity("北京");
        user1.setAddress(adder1);

        List<User> list = new ArrayList<User>();
        list.add(user);
        list.add(user1);

        return list;

    }


    @RequestMapping(value = "/set", method = RequestMethod.GET)
    @ResponseBody
    public String getAll() {

        return "selectAll ok";

    }

    @RequestMapping(value = "/set/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public String delet(@PathVariable int id) {

        return "delete ok" + id;

    }


}
